package 并发编程15.线程池;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author idea
 * @data 2019/2/22
 */
public class newSingleThreadExecutor {

    public static void main(String[] args) {
        //默认使用了无界队列
        ExecutorService executors = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 10; i++) {
            int index = i;
            executors.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + ":" + index);
                }
            });
        }
    }
}
